package com.yuanguangsheng.disk.file.service.impl;

import com.yuanguangsheng.disk.file.entity.SearchFileEntity;
import com.yuanguangsheng.disk.file.repository.FileDao;
import com.yuanguangsheng.disk.file.service.FileService;
import com.yuanguangsheng.disk.mybatis.entity.PtFileEntity;
import com.yuanguangsheng.disk.mybatis.flexigrid.PagingEntity;
import com.yuanguangsheng.disk.mybatis.flexigrid.TblResponseEntity;
import com.yuanguangsheng.disk.role.entity.SearchRoleEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FileServiceImpl implements FileService {
    @Resource
    private FileDao fileDao;

    @Override
    public void saveFileInfo(List<PtFileEntity> ptFileEntityList) {
        fileDao.deleteFileAll();
        fileDao.saveFileInfo(ptFileEntityList);
    }

    @Override
    public TblResponseEntity<PtFileEntity> queryFileInfoListByPage(SearchFileEntity entity, PagingEntity paging) {

        TblResponseEntity<PtFileEntity> tblResponseEntity = new TblResponseEntity<>();
        Integer total = fileDao.queryFileListTotal(entity);
        tblResponseEntity.setTotal(total);
        //计算当前页数
        paging.deal(PtFileEntity.class,total);
        tblResponseEntity.setPage(paging.getPage());

        List<PtFileEntity> list = fileDao.queryFileInfoListByPage(entity,paging);
        tblResponseEntity.setRawRecords(list);

        tblResponseEntity.deal();

        return tblResponseEntity;
    }

    @Override
    public PtFileEntity queryFileInfoById(String fileUuid) {
        return fileDao.queryFileInfoById(fileUuid);
    }

    @Override
    public List<PtFileEntity> queryFileListAll() {
        return fileDao.queryFileListAll();
    }


}
